package com.zy.openchat.core.model.message;

import com.zy.openchat.Constants;
import com.zy.openchat.util.Common;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class MessageReaction {

    public long userId;
    public int reactionId;

    public MessageReaction(long userId, int reactionId) {
        this.userId = userId;
        this.reactionId = reactionId;
    }

    public List<Long> userIds;

    public void appendUserId(long userId){
        if(userIds==null){
            userIds = new ArrayList<>();
            userIds.add(userId);
        }else  if(!userIds.contains(userId)){
            if(userIds.size()>= Constants.Max_Message_Reaction_Count){
                return;
            }
            userIds.add(0,userId);
        }
    }

    public void removeUserId(long userId){
        if(Common.isEmpty(userIds)||!userIds.contains(userId)){
            return;
        }
        userIds.remove(userId);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MessageReaction reaction = (MessageReaction) o;
        return reactionId == reaction.reactionId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(reactionId);
    }
}
